import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:qaun_ni_dev/provider/attributeProvide.dart';

class AttributeAdd extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('添加属性'),
      ),
      body: Container(
        padding: EdgeInsets.all(10),
        child: ListView(
          children: <Widget>[
            _inputAddText(context)
          ],
        ),
      ),
    );
  }


  Widget _inputAddText (context) {
    TextEditingController code = TextEditingController();
    TextEditingController type = TextEditingController();
    TextEditingController description = TextEditingController();
    TextEditingController val = TextEditingController();

    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(bottom: 15),
          padding: EdgeInsets.only(top: 2),
          child: TextField(
            controller: code,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '属性code',
              hintText: '请输入你的code值',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: type,
            readOnly: false,
            obscureText: true,
            decoration: InputDecoration(
              labelText: '属性类型',
              hintText: '请输入属性类型',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: val,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '属性键值',
              hintText: '请输入属性键值',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),

        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: description,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '属性描述',
              hintText: '请输入描述信息',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Row(
          children: <Widget>[
            Expanded(
              child: Container(
                margin: EdgeInsets.only(right: 20),
                child: RaisedButton(
                  color: Colors.lightBlue,
                  child: Text('提交新增',style: TextStyle(color: Colors.white),),
                  onPressed: () async {
                    var formData = {
                      'code':code.text,
                      'type':type.text,
                      'description':description.text,
                      'val':val.text,
                    };
                    Provider.of<AttributeProvide>(context,listen: false).addAttribute(context,formData);
                  },
                ),
              ),
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.only(right: 20),
                child:  RaisedButton(
                  child: Text('重置数据'),
                  onPressed: () {
                    code.text = '';
                    type.text = '';
                    val.text = '';
                    description.text = '';
                  },
                ),
              ),
            )
          ],
        )
      ],
    );
  }



}
